var t = getApp();

Page({
    data: {
        explainShow: !1,
        unpackingShow: !1,
        scrollViewWidth: 0,
        scrollLeft: 0,
        activeIndex: 0,
        scrollIntoView: "",
        allDataList: {},
        inShow: !1,
        info: !1
    },
    onShow: function() {
        this.setData({
            info: !0
        });
    },
    onHide: function() {
        this.setData({
            info: !1
        });
    },
    onLoad: function(a) {
        var e = this;
        if (wx.createSelectorQuery().select("#new-blind-box").boundingClientRect(function(t) {
            e.setData({
                scrollViewWidth: t.width
            });
        }).exec(), a.scene) {
            var i = decodeURIComponent(a.scene);
            if (i) {
                var n = [];
                n = i.split("&");
                for (var s = 0; s < n.length; s++) {
                    var c = [];
                    "id" == (c = n[s].split("="))[0] && this.getData(c[1].split(",")[0]), "mid" == c[0] && t._setMid(c[1]);
                }
            }
        } else this.getData(a.id);
    },
    clickExplain: function() {
        this.setData({
            explainShow: !0
        });
    },
    clickClose: function() {
        this.setData({
            explainShow: !1
        });
    },
    clickUnpacking: function() {
        1 === this.data.allDataList.list[this.data.activeIndex].show_status && this.setData({
            unpackingShow: !0
        });
    },
    cancalEvent: function(t) {
        this.setData({
            unpackingShow: !1
        });
    },
    chooseLevel: function(t) {
        var a = t.currentTarget.offsetLeft;
        this.setData({
            scrollLeft: a - this.data.scrollViewWidth / 2 + 50,
            activeIndex: t.currentTarget.dataset.index
        });
    },
    prevImg: function() {
        if (this.data.activeIndex) {
            var t = JSON.parse(JSON.stringify(this.data.activeIndex));
            this.setData({
                scrollIntoView: "item".concat(t - 2 >= 0 ? t - 2 : 0),
                activeIndex: this.data.activeIndex <= 0 ? 0 : this.data.activeIndex - 1
            }), 0 == this.data.activeIndex && this.setData({
                scrollLeft: 0
            });
        }
    },
    nextImg: function() {
        this.data.allDataList.list.length - 1 <= this.data.activeIndex || this.setData({
            scrollIntoView: "item".concat(this.data.activeIndex),
            activeIndex: this.data.activeIndex + 1
        });
    },
    getData: function(a) {
        var e = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.new-blind-box.frontend.index.index"),
            data: {},
            success: function(t) {
                var i = t.data;
                if (i.result) {
                    var n = a ? i.data.list.findIndex(function(t) {
                        return t.id == a;
                    }) : 0;
                    e.setData({
                        allDataList: i.data,
                        scrollIntoView: n - 1 <= 0 ? "" : "item".concat(n - 1),
                        activeIndex: n,
                        inShow: !0
                    });
                } else wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});